


    <?php 

$cs = Yii::app ()->getClientScript (); 
$cs = Yii::app ()->getClientScript()->registerCoreScript ('jquery'); 
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/menu/jquery.fixedMenu.js");
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/fancybox/jquery.fancybox-1.3.4.js");
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/fancybox/jquery.mousewheel-3.0.4.pack.js");
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/menu/jquery.opacityrollover.js");
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/menu/jquery.galleriffic.js");
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/menu/jquery.history.js");

    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/Three.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Color.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Vector2.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Vector3.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Vector4.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Ray.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Rectangle.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Matrix3.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Matrix4.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Object3D.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Quaternion.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Vertex.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Face3.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Face4.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/UV.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Geometry.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Spline.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/core/Edge.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/cameras/Camera.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/lights/Light.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/lights/AmbientLight.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/lights/DirectionalLight.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/lights/PointLight.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/lights/SpotLight.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/materials/Material.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/materials/LineBasicMaterial.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/materials/MeshBasicMaterial.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/materials/MeshLambertMaterial.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/materials/MeshPhongMaterial.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/materials/MeshDepthMaterial.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/materials/MeshNormalMaterial.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/materials/MeshFaceMaterial.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/materials/MeshShaderMaterial.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/materials/ParticleBasicMaterial.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/materials/ParticleCanvasMaterial.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/materials/ParticleDOMMaterial.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/textures/Texture.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/textures/DataTexture.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/objects/Particle.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/objects/ParticleSystem.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/objects/Line.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/objects/Mesh.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/objects/Bone.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/objects/SkinnedMesh.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/objects/Ribbon.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/objects/LOD.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/objects/Sprite.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/scenes/Scene.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/scenes/Fog.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/scenes/FogExp2.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/renderers/Projector.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/renderers/DOMRenderer.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/renderers/CanvasRenderer.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/renderers/SVGRenderer.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/renderers/WebGLShaders.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/renderers/WebGLRenderer.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/renderers/WebGLRenderTarget.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/renderers/WebGLRenderTargetCube.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/renderers/renderables/RenderableVertex.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/renderers/renderables/RenderableFace3.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/renderers/renderables/RenderableFace4.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/renderers/renderables/RenderableObject.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/renderers/renderables/RenderableParticle.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/renderers/renderables/RenderableLine.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/ColorUtils.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/GeometryUtils.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/ImageUtils.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/SceneUtils.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/ShaderUtils.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/animation/AnimationHandler.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/animation/Animation.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/cameras/FirstPersonCamera.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/cameras/PathCamera.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/cameras/FlyCamera.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/cameras/RollCamera.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/cameras/TrackballCamera.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/cameras/QuakeCamera.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/core/Curve.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/core/CurvePath.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/core/Path.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/core/Shape.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/core/TextPath.js"); 
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/geometries/CubeGeometry.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/geometries/CylinderGeometry.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/geometries/ExtrudeGeometry.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/geometries/IcosahedronGeometry.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/geometries/LatheGeometry.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/geometries/PlaneGeometry.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/geometries/SphereGeometry.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/geometries/TextGeometry.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/geometries/TorusGeometry.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/geometries/TorusKnotGeometry.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/loaders/Loader.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/loaders/JSONLoader.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/loaders/BinaryLoader.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/loaders/SceneLoader.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/loaders/UTF8Loader.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/objects/MarchingCubes.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/objects/Trident.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/physics/Collisions.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/physics/CollisionUtils.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/renderers/AnaglyphWebGLRenderer.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/extras/renderers/CrosseyedWebGLRenderer.js");

    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/RequestAnimationFrame.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/fonts/helvetiker_regular.typeface.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/Stats.js");
    
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/menu/jquery.fixedMenu.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/menu/dock.js");
    $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/threejs/Detector.js");


?>
    <script type="text/javascript">
    
    $(function(){
    if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
      var container, stats;
      var camera, scene, renderer;
      var projector, plane, cube;
      var mouse2D, mouse3D, ray,
      rollOveredFace, isShiftDown = false,
      theta = 45, isCtrlDown = false;

      var rollOverMesh, rollOverMaterial, voxelPosition = new THREE.Vector3(), tmpVec = new THREE.Vector3();
      var cubeGeo, cubeMaterial;
      var i, intersector;

      init();
      animate();
    });
      



      function init() {

        container = document.createElement( 'div' );
        document.body.appendChild( container );

        var info = document.createElement( 'div' );
        info.style.position = 'absolute';
        info.style.top = '10px';
        info.style.width = '100%';
        info.style.textAlign = 'center';
        info.innerHTML = '<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - voxel painter - webgl<br /><strong>click</strong>: add voxel, <strong>control + click</strong>: remove voxel, <strong>shift + click</strong>: rotate, <a href="javascript:save();return false;">save .png</a>';
        container.appendChild( info );

        camera = new THREE.Camera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
        camera.position.y = 800;
        camera.target.position.y = 200;

        scene = new THREE.Scene();

        // roll-over helpers

        rollOverGeo = new THREE.CubeGeometry( 50, 50, 50 );
        rollOverMaterial = new THREE.MeshBasicMaterial( { color: 0xff0000, opacity: 0.5, transparent: true } );
        rollOverMesh = new THREE.Mesh( rollOverGeo, rollOverMaterial );
        scene.addObject( rollOverMesh );


        // cubes

        cubeGeo = new THREE.CubeGeometry( 50, 50, 50 );
        cubeMaterial = new THREE.MeshLambertMaterial( { color: 0x00ff80, shading: THREE.FlatShading, map: THREE.ImageUtils.loadTexture( "textures/square-outline-textured.png" ) } );
        cubeMaterial.color.setHSV( 0.1, 0.7, 1.0 );
        // picking

        projector = new THREE.Projector();

        // grid

        plane = new THREE.Mesh( new THREE.PlaneGeometry( 1000, 1000, 20, 20 ), new THREE.MeshBasicMaterial( { color: 0x555555, wireframe: true } ) );
        plane.rotation.x = - 90 * Math.PI / 180;
        scene.addObject( plane );

        mouse2D = new THREE.Vector3( 0, 10000, 0.5 );
        ray = new THREE.Ray( camera.position, null );

        // Lights

        var ambientLight = new THREE.AmbientLight( 0x606060 );
        scene.addLight( ambientLight );

        var directionalLight = new THREE.DirectionalLight( 0xffffff );
        directionalLight.position.x = Math.random() - 0.5;
        directionalLight.position.y = Math.random() - 0.5;
        directionalLight.position.z = Math.random() - 0.5;
        directionalLight.position.normalize();
        scene.addLight( directionalLight );

        var directionalLight = new THREE.DirectionalLight( 0x808080 );
        directionalLight.position.x = Math.random() - 0.5;
        directionalLight.position.y = Math.random() - 0.5;
        directionalLight.position.z = Math.random() - 0.5;
        directionalLight.position.normalize();
        scene.addLight( directionalLight );

        renderer = new THREE.WebGLRenderer( { antialias: true } );
        renderer.setSize( window.innerWidth, window.innerHeight );

        container.appendChild( renderer.domElement );

        stats = new Stats();
        stats.domElement.style.position = 'absolute';
        stats.domElement.style.top = '0px';
        container.appendChild( stats.domElement );

        document.addEventListener( 'mousemove', onDocumentMouseMove, false );
        document.addEventListener( 'mousedown', onDocumentMouseDown, false );
        document.addEventListener( 'keydown', onDocumentKeyDown, false );
        document.addEventListener( 'keyup', onDocumentKeyUp, false );

      }

      function getRealIntersector( intersects ) {

        for( i = 0; i < intersects.length; i++ ) {

          intersector = intersects[ i ];

          if ( intersector.object != rollOverMesh ) {

            return intersector;

          }

        }

        return null;

      }

      function setVoxelPosition( intersector ) {

        tmpVec.copy( intersector.face.normal );

        voxelPosition.add( intersector.point, intersector.object.matrixRotationWorld.multiplyVector3( tmpVec ) );

        voxelPosition.x = Math.floor( voxelPosition.x / 50 ) * 50 + 25;
        voxelPosition.y = Math.floor( voxelPosition.y / 50 ) * 50 + 25;
        voxelPosition.z = Math.floor( voxelPosition.z / 50 ) * 50 + 25;

      }

      function onDocumentMouseMove( event ) {

        event.preventDefault();

        mouse2D.x = ( event.clientX / window.innerWidth ) * 2 - 1;
        mouse2D.y = - ( event.clientY / window.innerHeight ) * 2 + 1;

      }

      function onDocumentMouseDown( event ) {

        event.preventDefault();

        var intersects = ray.intersectScene( scene );

        if ( intersects.length > 0 ) {

          intersector = getRealIntersector( intersects );

          // delete cube

          if ( isCtrlDown ) {

            if ( intersector.object != plane ) {

              scene.removeObject( intersector.object );

            }

          // create cube

          } else {

            intersector = getRealIntersector( intersects );
            setVoxelPosition( intersector );

            var voxel = new THREE.Mesh( cubeGeo, cubeMaterial );
            voxel.position.copy( voxelPosition );
            voxel.matrixAutoUpdate = false;
            voxel.updateMatrix();
            scene.addObject( voxel );

          }

        }
      }

      function onDocumentKeyDown( event ) {

        switch( event.keyCode ) {

          case 16: isShiftDown = true; break;
          case 17: isCtrlDown = true; break;

        }

      }

      function onDocumentKeyUp( event ) {

        switch( event.keyCode ) {

          case 16: isShiftDown = false; break;
          case 17: isCtrlDown = false; break;

        }
      }

      function save() {

        window.open( renderer.domElement.toDataURL('image/png'), 'mywindow' );

      }

      //

      function animate() {

        requestAnimationFrame( animate );

        render();
        stats.update();

      }

      function render() {

        if ( isShiftDown ) {

          theta += mouse2D.x * 3;

        }

        mouse3D = projector.unprojectVector( mouse2D.clone(), camera );
        ray.direction = mouse3D.subSelf( camera.position ).normalize();

        var intersects = ray.intersectScene( scene );

        if ( intersects.length > 0 ) {

          intersector = getRealIntersector( intersects );
          if ( intersector ) {

            setVoxelPosition( intersector );
            rollOverMesh.position = voxelPosition;

          }

        }

        camera.position.x = 1400 * Math.sin( theta * Math.PI / 360 );
        camera.position.z = 1400 * Math.cos( theta * Math.PI / 360 );

        renderer.render( scene, camera );

      }

    </script>